﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElfTyping.Animations;

namespace ElfTyping.States.StoryState
{
    public class SetCharacterAction : StoryAction
    {
        static Dictionary<string, Portraits> CharacterMap = new Dictionary<string, Portraits>()
        {
            {"", new Portraits(null, null)},
            {"RHYS", new Portraits(new RhysPortrait(true), new RhysPortrait(false))},
            {"SOREN", new Portraits(new SorenPortrait(true), new SorenPortrait(false))},
            {"SHINON", new Portraits(new ShinonPortrait(true), new ShinonPortrait(false))},
            {"REYSON", new Portraits(new ReysonPortrait(true), new ReysonPortrait(false))},
            {"TIBARN", new Portraits(new TibarnPortrait(true), new TibarnPortrait(false))},
            {"PLEASURE", new Portraits(null, new Animation(@"Textures\CG\SerenesElves-2"))},
            {"PAIN", new Portraits(null, new Animation(@"Textures\CG\SerenesElves-1"))},
        };

        string Name;
        bool IsLeftSide;
        Portraits portraits = null;

        public SetCharacterAction(StoryState storyState, string characterName, bool isLeft)
            : base(storyState)
        {
            Name = characterName;
            IsLeftSide = isLeft;
            portraits = CharacterMap[Name.ToUpper()];
        }

        public override void OnEnd()
        {
            if (IsLeftSide)
            {
                StoryState.LeftCharacter = portraits.BigPortrait;
                StoryState.LeftCharacterBottomLeft = FireEmblemPortraitAnimation.BigPortraitLeftPosition;
                StoryState.LeftCharacterName = Name;
                StoryState.LeftCharacterPortrait = portraits.SmallPortrait;
            }
            else
            {
                StoryState.RightCharacter = portraits.BigPortrait;
                StoryState.RightCharacterBottomLeft = FireEmblemPortraitAnimation.BigPortraitRightPosition;
                StoryState.RightCharacterName = Name;
                StoryState.RightCharacterPortrait = portraits.SmallPortrait;
            }

            base.OnEnd();
        }

        private class Portraits
        {
            public FireEmblemPortraitAnimation BigPortrait { get; set; }
            public Animation SmallPortrait { get; set; }
            public Portraits(FireEmblemPortraitAnimation big, Animation small)
            {
                BigPortrait = big;
                SmallPortrait = small;
            }
        }
    }
}
